//
//  ViewController.swift
//  TCMHealth
//
//  Created by 韩颖 on 2023/7/2.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var userInfoTableView: UITableView!
    var todayUserList = [UserInfo]()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        configTable()
        reloadDate()
    }
    
    func reloadDate(){
        
    }
    
    func reloadAddDate(){
        
    }
    
    func configTable() {
        userInfoTableView.register(UINib.init(nibName: "UserInfoCell", bundle: nil), forCellReuseIdentifier: "UserInfoCell")

    }
    
    @IBAction func addUserAction(_ sender: Any) {
        let addUserVC = AddUserViewController()
        addUserVC.modalPresentationStyle = .overFullScreen
        addUserVC.reloadData = {
            self.reloadAddDate()
        }
        self.present(addUserVC, animated: true, completion: nil)
    }
    
}

extension ViewController: UITableViewDelegate, UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerView = UIView.init(frame: CGRect.init(x: 20, y: 0, width: 200, height: 28))
        headerView.backgroundColor = .white
        let label = UILabel.init(frame: CGRect.init(x: 20, y: 10, width: 180, height: 28))
        label.font = UIFont.boldSystemFont(ofSize: 25)
        label.textColor = .black
        if section == 0 {
            label.text = "7月20日"
        }else{
            label.text = "7月21日"
        }
//        label.text =  Date.createDateStr(createdStr: userList[section].dayTime)
        headerView.addSubview(label)
        return headerView
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 40
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let nameArray1 = ["王晓宇","孙广志","周树同"]
        let nameArray2 = ["周磊","王斌","李丽"]
        let desArray = ["头疼，发烧","浑身乏力","胃胀胃痛"]
        let userInfocell = tableView.dequeueReusableCell(withIdentifier: "UserInfoCell", for: indexPath) as! UserInfoCell
//        userInfocell.userInfo = userList[indexPath.section].users[indexPath.row]
        if indexPath.section == 0{
            userInfocell.userNameLable.text = nameArray1[indexPath.row]
        }else {
            userInfocell.userNameLable.text = nameArray2[indexPath.row]
        }
        userInfocell.desLabel.text = desArray[indexPath.row]
        return userInfocell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let userDetailVC = UserDetailViewController()
        userDetailVC.modalPresentationStyle = .overFullScreen
        self.present(userDetailVC, animated: true)
    }
}

